package org.apache.ibatis.demo.generator;

import java.util.Random;

/**
 * NameGenerator
 *
 * @author zhaohui
 * @date 2019/12/12 17:22
 */
public class NameGenerator {

    public static String randomChineseName() {
        return 0 == new Random().nextInt(2) ? randomChineseName2() : randomChineseName3();
    }

    private static String randomChineseName2() {
        return randomChineseName(2);
    }

    private static String randomChineseName3() {
        return randomChineseName(3);
    }

    private static String randomChineseName(int length) {
        Random random = new Random();
        int indexFirstName = random.nextInt(DataDict.FIRST_NAME_CN.length);
        StringBuilder nameBuffer = new StringBuilder();
        nameBuffer.append(DataDict.FIRST_NAME_CN[indexFirstName]);
        for (int i = 1; i <= length - 1; i++) {
            int indexLastName = random.nextInt(DataDict.LAST_NAME_CN.length);
            nameBuffer.append(DataDict.LAST_NAME_CN[indexLastName]);
        }
        return nameBuffer.toString();
    }

}
